﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ScrumFactory.Windows {
    /// <summary>
    /// Interaction logic for AlertMessage.xaml
    /// </summary>
    public partial class AlertMessage : UserControl, IMessageBoxView {

        public static readonly DependencyProperty ModelProperty =
            DependencyProperty.Register("Model", typeof(ViewModel.IMessageBoxViewModel), typeof(AlertMessage), new PropertyMetadata(OnModelChanged));

        private static void OnModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
            AlertMessage message = d as AlertMessage;
            if (message == null)
                return;
            ViewModel.IMessageBoxViewModel value = e.NewValue as ViewModel.IMessageBoxViewModel;
            if (value == null)
                return;
            message.Model = value;            
        }

        public AlertMessage() {
            InitializeComponent();            
        }

        public ViewModel.IMessageBoxViewModel Model {
            get {
                return GetValue(ModelProperty) as ViewModel.IMessageBoxViewModel;
            }
            set {
                SetValue(ModelProperty, value);                
                DataContext = value;
                ViewModel.IMessageBoxViewModel model = value as ViewModel.MessageBoxViewModel;
                model.View = this;
            }
        }

        public void Show() {
            this.Visibility = Visibility.Visible;
        }

        public void Close() {
            this.Visibility = Visibility.Collapsed;
        }

        public void DragMove() {
            throw new NotSupportedException();
        }

    }
}
